<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>sentox-Draggable</title>
		<link type="text/css" rel="stylesheet" href="../css/themes/sentox/easyui.css" />
		<link type="text/css" rel="stylesheet" href="../css/themes/sentox/font-awesome.min.css">

		<script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
	</head>

	<body style="margin:10px;">
		<h2>Basic Draggable</h2>
		<p>Move the boxes below by clicking on it with mouse.</p>
		<div style="margin:20px 0;"></div>
		<div class="easyui-draggable" style="width:200px;height:150px;background:#1ab394;border:1px solid #ccc"></div>
		<div class="easyui-draggable" data-options="handle:'#title'" style="width:200px;height:150px;background:#fafafa;border:1px solid #ccc;margin-top:10px">
			<div id="title" style="padding:5px;background:#1ab394;color:#fff">Title</div>
		</div>
		
		<!----------------------------------------------------------------------------------------------------------------------------->
		<h2>Snap Draggable</h2>
		<p>This sample shows how to snap a draggable object to a 20x20 grid.</p>
		<div style="margin:20px 0;"></div>
		<div class="easyui-panel" style="position:relative;overflow:hidden;width:500px;height:300px;">
			<div class="easyui-draggable" data-options="onDrag:onDrag" style="width:100px;height:100px;background:#fafafa;border:1px solid #ccc;">
			</div>
		</div>
		<script>
			function onDrag(e){
				var d = e.data;
				d.left = repair(d.left);
				d.top = repair(d.top);
				
				function repair(v){
					var r = parseInt(v/20)*20;
					if (Math.abs(v % 20) > 10){
						r += v > 0 ? 20 : -20;
					}
					return r;
				}
			}
		</script>
		
		<!----------------------------------------------------------------------------------------------------------------------------->
		<h2>Constrain Draggable</h2>
		<p>The draggable object can only be moved within its parent container.</p>
		<div style="margin:20px 0;"></div>
		<div class="easyui-panel" style="position:relative;overflow:hidden;width:500px;height:300px">
			<div class="easyui-draggable" data-options="onDrag:onDrag" style="width:100px;height:100px;background:#fafafa;border:1px solid #ccc;">
			</div>
		</div>
		<script>
			function onDrag(e){
				var d = e.data;
				if (d.left < 0){d.left = 0}
				if (d.top < 0){d.top = 0}
				if (d.left + $(d.target).outerWidth() > $(d.parent).width()){
					d.left = $(d.parent).width() - $(d.target).outerWidth();
				}
				if (d.top + $(d.target).outerHeight() > $(d.parent).height()){
					d.top = $(d.parent).height() - $(d.target).outerHeight();
				}
			}
		</script>
		
		
		
	</body>

</html>